package cn.com.yusys.yusp.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import cn.com.yusys.yusp.commons.dto.Contr;
import cn.com.yusys.yusp.commons.dto.DataContr;
import cn.com.yusys.yusp.commons.dto.MenuContr;
import cn.com.yusys.yusp.commons.dto.User;
import cn.com.yusys.yusp.commons.service.UserService;

@Service
public class UserServiceCacheImpl implements UserService{
	@Autowired
	private UserProviderService userProviderService;
	
	@Override
	@Cacheable(value = "contrurl", key = "'findAllContrUrl'",unless="#result == null")
	public List<? extends Contr> findAllContrUrl(String accessToken) {
		return userProviderService.getAllContrUrl();
	}
	
	@Override
	@Cacheable(value = "sessionInfo", key = "'userCode_'+#accessToken",unless="#result == null")
	public String getUserCode(String accessToken) {
		return userProviderService.getUserCode();
	}

	@Override
	@Cacheable(value = "sessionInfo", key = "#accessToken",unless="#result == null")
	public User getUserInfo(String loginCode, String sysId, String accessToken) {
		return userProviderService.getUserInfo(loginCode, sysId);
	}

	@Override
	@Cacheable(value = "sessionInfo", key = "'menuandContr_'+#accessToken",unless="#result == null")
	public MenuContr getMenuandContr(String loginCode, String sysId, String accessToken) {
		return userProviderService.getMenuandContr(loginCode,sysId);
	}

	@Override
	@Cacheable(value = "sessionInfo", key = "'dataContr_'+#accessToken",unless="#result == null")
	public List<? extends DataContr> getDataAuth(String loginCode, String sysId, String accessToken) {
		return userProviderService.getDataAuth(loginCode,sysId);
	}

	@Override
	@CacheEvict(value = "contrurl", key = "'getAllContrUrl'", beforeInvocation = true)
	public void cleanAllContrUrlCache() {
		
	}

	@Override
	@CacheEvict(value = "sessionInfo", key = "#accessToken", beforeInvocation = true)
	public void cleanUserInfoCache(String accessToken) {
		
	}

	@Override
	@CacheEvict(value = "sessionInfo", key = "'menuandContr_'+#accessToken", beforeInvocation = true)
	public void cleanMenuAndContrCache(String accessToken) {

	}

	@Override
	@CacheEvict(value = "sessionInfo", key = "'dataContr_'+#accessToken", beforeInvocation = true)
	public void cleanDataContrCache(String accessToken) {
		
	}
}
